# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Ray Donnelly <mingw.android@gmail.com>

_pyname=Pygments
_realname=pygments
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=2.15.1
pkgrel=4
pkgdesc="Python syntax highlighter (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
license=('BSD')
url="https://pygments.org/"
depends=("${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python-wheel"
             "${MINGW_PACKAGE_PREFIX}-python-docutils"
             "${MINGW_PACKAGE_PREFIX}-python-sphinx"
             "${MINGW_PACKAGE_PREFIX}-python-wcag-contrast-ratio")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pytest"
              "${MINGW_PACKAGE_PREFIX}-python-lxml")
options=(!strip)
source=("https://pypi.org/packages/source/P/Pygments/${_pyname}-${pkgver}.tar.gz")
sha256sums=('8ace4d3c1dd481894b2005f560ead0f9f19ee64fe983366be1a21e171d12775c')

prepare() {
  rm -rf python-build-${MSYSTEM} | true
  cp -r ${_pyname}-${pkgver} python-build-${MSYSTEM}
}

build () {
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
  make -C doc html
}

check() {
  msg "Python test for ${MSYSTEM}"
  cd "${srcdir}/python-build-${MSYSTEM}"
  PYTHONDONTWRITEBYTECODE=1 \
  ${MINGW_PREFIX}/bin/pytest
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"

  mkdir -p "$pkgdir${MINGW_PREFIX}/share/doc"
  cp -rT doc/_build/html "$pkgdir${MINGW_PREFIX}/share/doc/${_realname}"
  install -Dm644 doc/pygmentize.1 -t "$pkgdir${MINGW_PREFIX}/share/man/man1"
}
